package com.alibaba.aone.casestudy.module.screen;

import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.aone.casestudy.common.WebConstant;
import com.alibaba.aone.casestudy.common.entity.AoneDepart;
import com.alibaba.aone.casestudy.common.entity.AoneUser;
import com.alibaba.aone.casestudy.service.AoneUserService;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.TurbineRunDataInternal;
import com.alibaba.citrus.turbine.dataresolver.Param;

public class Search {
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private AoneUserService userService;

	public void execute(Context context,@Param("q") String keyword) {

		TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
		String cookie = rundata.getCookies().getString(
				WebConstant.AONE_COOKIE_LOGIN_NAME);
		context.put("loginName", cookie);
		String userNames = userService.autoCompelteSearchUser(keyword, 0,20);

		context.put("userNames", userNames);
	}
}
